﻿namespace ThreeByte.ActiveDeck.Dashboard
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using System;
    using ActiveDeck.Dashboard.LoginUI;
    using System.Windows.Data;
    using System.ComponentModel;
    using ThreeByte.ActiveDeck.Web.Models;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class Participants : Page
    {
        /// <summary>
        /// Creates a new <see cref="Participants"/> instance.
        /// </summary>
        public Participants() {
            InitializeComponent();

        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e) {

        }

        private void DashboardDataSource_LoadedData(object sender, LoadedDataEventArgs e) {
            //PagedCollectionView pcv = new PagedCollectionView(e.AllEntities);

            //pcv.GroupDescriptions.Add(new PropertyGroupDescription("PresentationID"));

            //UserDataGrid.DataContext = pcv;
        }

        private void ApproveButton_Click(object sender, System.Windows.RoutedEventArgs e) {
            Button button = (Button)sender;

            ApprovedUser user = (ApprovedUser)(button.Tag);
            user.Approved = true;
            user.Blocked = null;
            user.ApprovedAt = DateTime.Now;
            user.ApprovedBy = WebContext.Current.User.Name;
            
            DashboardDataSource.SubmitChanges();
        }

        private void BlockButton_Click(object sender, System.Windows.RoutedEventArgs e) {
            Button button = (Button)sender; 
            ApprovedUser user = (ApprovedUser)(button.Tag);
            user.Blocked = true;

            DashboardDataSource.SubmitChanges();
        }

        private void UnapproveButton_Click(object sender, System.Windows.RoutedEventArgs e) {
            Button button = (Button)sender; 
            ApprovedUser user = (ApprovedUser)(button.Tag);
            user.Approved = false;
            user.ApprovedAt = null;
            user.ApprovedBy = null;

            DashboardDataSource.SubmitChanges();
        }
    }
}